
#include "Socket.hpp"
#include "client.hpp"
#include "ansi.hpp"
#include "character.hpp"

using namespace std;

#define outb(s,m)     (Socket::WriteLine(s,m))
#define BUFFSZ		64

void	GetStartingInfo(Client * c,Character *ch);
void	GetBaseAttributes(Client * c,Character *ch);
void	GetBackground(Client * c,Character *ch);
void	GetOccupation(Client * c,Character *ch);
void	GetProfession(Client * c,Character *ch);
void	GetWpnProficiencies(Client * c,Character *ch);
void	GetSkills(Client * c,Character *ch);
void	GetFeats(Client * c,Character *ch);
void	GetDesc(Client * c,Character *ch);

static void Title(int,const char *t);

// The -1's are placeholders/fillers for 0 to 7.  Stats start at 8 which costs
// 0 points. Each subsequent raising of stat costs 1 point up to level 14 then
// it costs 2 points per point of stat thereafter.
static int PointBuy[] = {
		-1,-1,-1,-1,-1,-1,-1,-1,
		0,1,2,3,4,5,6,8,10,12,14,16,18,20,22,24,26,28,30
};

/*******************************************************************************
 * 1. Get name, age, gender, height, weight, eyes, hair, skin
 * 2. Get primary attributes
 * 3. Background
 * 4. Occupation
 * 5. Profession
 * 6. Weapon proficiencies
 * 7. Skills
 * 8. Feats (if any)
 * 9. Bio/Description
 */
void NewCharacter(Client * c)
{
    char    choice[5];
    int     s = c->Sock();
    Socket::WriteLine(s,":new character|");
    int     pts = 30;
    
    Title(s,"New Character Creation");

    Character * addme = new Character();

    GetStartingInfo(c,addme);
    GetBaseAttributes(c,addme);



}

void	GetStartingInfo(Client * c, Character * ch)
{
	int s = c->Sock();
	char email[BUFFSZ];
	char fname[BUFFSZ];
	char lname[BUFFSZ];
	char codename[BUFFSZ];
	char buff[BUFFSZ];
	std::string		str;

loop:
	outb(s,"I'll collect your login name and superficial attributes now.");
	outb(s,"Your email address is used as a unique login name. We never share");
	outb(s,"your personal information to any third parties.");
	Socket::Write(s,"Email address: ");
	Socket::ReadLine(s,email,BUFFSZ);
	str = email;
	c->SetUserName(str);
	outb(s,"What name will you go by?  Inane, offensive, or OOC names may be deleted.");
	Socket::Write(s,"First name: ");
	Socket::ReadLine(s,fname,BUFFSZ);
	Socket::Write(s,"Last name: ");
	Socket::ReadLine(s,lname,BUFFSZ);
	std::string n = fname;
	n += " "; n += lname;
	ch->SetFullName(n);
	outb(s,"Next is your codename. This name is what is seen mostly online.");
	Socket::Write(s,"Codename: ");
	Socket::ReadLine(s,codename,BUFFSZ);
	str = codename;
	ch->SetCodename(str);
	Socket::Write(s,"What is your character's age? ");
	Socket::ReadLine(s,buff,BUFFSZ);
	str = buff;
	ch->SetAge(str);
	Socket::Write(s,"Height (feet)? ");
	Socket::ReadLine(s,buff,BUFFSZ);
	str = buff;
	ch->SetHeight(str);
	Socket::Write(s,"Weight (lbs)? ");
	Socket::ReadLine(s,buff,BUFFSZ);
	str = buff;
	ch->SetWeight(str);
	Socket::Write(s,"Eye color? ");
	Socket::ReadLine(s,buff,BUFFSZ);
	str = buff;
	ch->SetEyes(str);
	Socket::Write(s,"Hair color? ");
	Socket::ReadLine(s,buff,BUFFSZ);
	str = buff;
	ch->SetHair(str);
	// TODO not asking about skin tone at this point.

	outb(s,"Ok, thanks. Here's what I've got so far...");
	Socket sock(s);
	sock << "Login: " << c->Name().data() << "\r\n";
	sock << "Full name: " << ch->FullName() << "\r\n";
	sock << "Code name: " << ch->Codename() << "\r\n";
	sock << "Age: " << ch->Age() << " Height: " << ch->Height() <<
			" Weight: " << ch->Weight() << "\r\n";
	sock << "Eyes: " << ch->Eyes() << " Hair: " << ch->Hair() << "\r\n" << "\r\n";


	outb(s,"Is this correct (Y/n)? ");
	Socket::ReadLine(s,buff,BUFFSZ);
	if (buff[0] == 'n' || buff[0] == 'N')
		goto loop;


}
void	GetBaseAttributes(Client * c, Character * ch)
{
	char choice[5];
	int s = c->Sock();

    while(choice[0] != 'y')
    {
        // you have 30 pts
        // attribute pts 9 - 14 cost 1pt/per. 14+ cost 2pt/per attribute pt.
        BaseStat & baseStats = ch->Base();
        DerivedStat & derivedStats = ch->Derived();
        outb(s,"You have 30 points.  Your stats start off at 8 and cost one point ");
        outb(s,"up to and including 14.  All 14+ attributes cost two points per ");
        outb(s,"attribute point above 14.");

		while (choice[0] != 'y' || choice[0] != 'Y')
		{
	       	outb(s,"Strength: "); 

			Socket::Write(s,"Keep these stats (y/n)? ");
			Socket::ReadLine(s,choice,5);
		}
    }

}
void	GetBackground(Client * c,Character *ch)
{

}
void	GetOccupation(Client * c,Character *ch)
{

}
void	GetProfession(Client * c,Character *ch)
{

}
void	GetWpnProficiencies(Client * c,Character *ch)
{

}
void	GetSkills(Client * c,Character *ch)
{

}
void	GetFeats(Client * c,Character *ch)
{

}
void	GetDesc(Client * c,Character *ch)
{

}



void Title(int s, const char * t)
{
    FONT_WHITE(s);
    Socket::Write(s,"[");
    FONT_YELLOW(s);
    Socket::Write(s,t);
    FONT_WHITE(s);
    Socket::WriteLine(s,"]");
    FONT_NORMAL(s);
}
